package org.mat.ipaas.ucenter.bff.admin.modules.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysCommentRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysCommentDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.SysCommentFileVoDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.SysCommentVODTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统评论回复表
 */
@Api(tags = "系统评论回复表")
@RestController
@RequestMapping("/sys/comment")
@Slf4j
public class SysCommentController {

    @Autowired
    private SysCommentRestAPI sysCommentRestAPI;

    /**
     * 查询评论+文件
     *
     * @param sysCommentDTO
     * @return
     */
    @ApiOperation(value = "系统评论回复表-列表查询", notes = "系统评论回复表-列表查询")
    @GetMapping(value = "/listByForm")
    public MatApiResponse<IPage<SysCommentVODTO>> queryListByForm(SysCommentDTO sysCommentDTO) {
        MatApiResponse<IPage<SysCommentVODTO>> matApiResponse = sysCommentRestAPI.queryListByForm(sysCommentDTO);
        return matApiResponse;
    }

    /**
     * 查询文件
     *
     * @param sysCommentDTO
     * @return
     */
    @ApiOperation(value = "系统评论回复表-列表查询", notes = "系统评论回复表-列表查询")
    @GetMapping(value = "/fileList")
    public MatApiResponse<IPage<SysCommentFileVoDTO>> queryFileList(SysCommentDTO sysCommentDTO) {
        MatApiResponse<IPage<SysCommentFileVoDTO>> matApiResponse = sysCommentRestAPI.queryFileList(sysCommentDTO);
        return matApiResponse;
    }

    @ApiOperation(value = "系统评论表-添加文本", notes = "系统评论表-添加文本")
    @PostMapping(value = "/addText")
    public MatApiResponse<String> addText(@RequestBody SysCommentDTO sysCommentDTO) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.addText(sysCommentDTO);
        return matApiResponse;
    }

    @ApiOperation(value = "系统评论表-添加文件", notes = "系统评论表-添加文件")
    @PostMapping(value = "/addFile")
    public MatApiResponse<String> addFile(HttpServletRequest request) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.addFile(request);
        return matApiResponse;
    }

    @ApiOperation(value = "系统评论回复表-通过id删除", notes = "系统评论回复表-通过id删除")
    @DeleteMapping(value = "/deleteOne")
    public MatApiResponse<String> deleteOne(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.deleteOne(id);
        return matApiResponse;
    }


    /**
     * 获取文件预览的地址
     *
     * @return
     */
    @GetMapping(value = "/getFileViewDomain")
    public MatApiResponse<String> getFileViewDomain() {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.getFileViewDomain();
        return matApiResponse;
    }


    /**
     * 分页列表查询
     *
     * @param sysCommentDTO
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "系统评论回复表-分页列表查询", notes = "系统评论回复表-分页列表查询")
    @GetMapping(value = "/list")
    public MatApiResponse<IPage<SysCommentDTO>> queryPageList(SysCommentDTO sysCommentDTO,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              HttpServletRequest req) {
        MatApiResponse<IPage<SysCommentDTO>> matApiResponse = sysCommentRestAPI.queryPageList(sysCommentDTO, pageNo, pageSize, req);
        return matApiResponse;
    }


    /**
     * 添加
     *
     * @param sysCommentDTO
     * @return
     */
    @ApiOperation(value = "系统评论回复表-添加", notes = "系统评论回复表-添加")
    //@RequiresPermissions("org.mat.ipaas.sys.biz.modules.demo:sys_comment:add")
    @PostMapping(value = "/add")
    public MatApiResponse<String> add(@RequestBody SysCommentDTO sysCommentDTO) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.add(sysCommentDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysCommentDTO
     * @return
     */
    @ApiOperation(value = "系统评论回复表-编辑", notes = "系统评论回复表-编辑")
    //@RequiresPermissions("org.mat.ipaas.sys.biz.modules.demo:sys_comment:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<String> edit(@RequestBody SysCommentDTO sysCommentDTO) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.edit(sysCommentDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "系统评论回复表-通过id删除", notes = "系统评论回复表-通过id删除")
    //@RequiresPermissions("org.mat.ipaas.sys.biz.modules.demo:sys_comment:delete")
    @DeleteMapping(value = "/delete")
    public MatApiResponse<String> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "系统评论回复表-批量删除", notes = "系统评论回复表-批量删除")
    //@RequiresPermissions("org.mat.ipaas.sys.biz.modules.demo:sys_comment:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<String> matApiResponse = sysCommentRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "系统评论回复表-通过id查询", notes = "系统评论回复表-通过id查询")
    @GetMapping(value = "/queryById")
    public MatApiResponse<SysCommentDTO> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<SysCommentDTO> matApiResponse = sysCommentRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 导出excel
     *
     * @param sysCommentDTO
     */
    //@RequiresPermissions("org.mat.ipaas.sys.biz.modules.demo:sys_comment:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysCommentDTO sysCommentDTO) {
        ModelAndView modelAndView = sysCommentRestAPI.exportXls(sysCommentDTO);
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    //@RequiresPermissions("sys_comment:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse<?> importExcel() {
        MatApiResponse<?> matApiResponse = sysCommentRestAPI.importExcel();
        return matApiResponse;
    }


}
